import { onMounted, onUnmounted, reactive, toRefs } from "vue"

export const useMouse = function(){

    const mouse = reactive({x:0,y:0});

    const update = (e:MouseEvent)=>{
        mouse.x = e.pageX;
        mouse.y = e.pageY;
    }

    onMounted(()=>{
        window.addEventListener("mousemove",update);
    })

    onUnmounted(()=>{
        window.removeEventListener("mousemove",update);
    })

    return toRefs(mouse);
}